package com.zhaoyu.admin.controller;

import com.zhaoyu.admin.service.AdChannelService;
import com.zhaoyu.apis.admin.AdChannelControllerApis;
import com.zhaoyu.model.admin.dtos.ChannelDto;
import com.zhaoyu.model.admin.pojos.AdChannel;
import com.zhaoyu.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApis {

    @Autowired
    private AdChannelService channelService;

    @Override
    @PostMapping("/list") // json格式的数据
    public ResponseResult findByNameAndPageAdChannel(@RequestBody ChannelDto channelDto) {
        return channelService.findByNameAndPage(channelDto);
    }

    @Override
    @PostMapping("/save") // json格式的数据
    public ResponseResult saveAdChannel(@RequestBody AdChannel adChannel){
        return channelService.insert(adChannel);
    }

    @Override
    @PostMapping("/update") // json格式的数据
    public ResponseResult updateAdChannel(@RequestBody AdChannel adChannel){
        return channelService.edit(adChannel);
    }

    @Override
    @GetMapping("/del/{id}") // rest风格
    public ResponseResult deleteByIdAdChannel(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }

    @Override
    @GetMapping("/findAll")
    public ResponseResult findAllAdChannel() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }

}